/**
 * @USER: Administrator
 * @DATE: 2024/10/5 上午10:58
 * @VERSION: 1.0.0
 */
public class LC2765 {
    public static void main(String[] args) {
        LC2765 lc2765 = new LC2765();
        System.out.println(lc2765.alternatingSubarray(new int[]{2,3,4,3,4}));
    }

    public int alternatingSubarray(int[] nums) {
        int maxCount=-1;
        int count;
        for(int i=1; i<nums.length; i++){
            if(nums[i]-nums[i-1]==1){
                count=2;
                if(maxCount<count){
                    maxCount=count;
                }
                int j=i+1;
                for(; j<nums.length; j++){
                    if(nums[j]-nums[j-1]==Math.pow(-1,j-i)){
                        count++;
                        if(maxCount<count){
                            maxCount=count;
                        }
                    }else {
                        break;
                    }
                }
                i=j-1;
            }
        }
        return maxCount;
    }

}
